package com.zw.mes.module.tecdrawsign.service;

import com.zw.mes.entity.technology.DrawLssue;
import com.zw.mes.entity.technology.DrawSign;
import com.zw.mes.module.tecdrawsign.mapper.DrawSignMapper;
import com.zw.mes.module.tecdrawsign.model.DictEnum;
import com.zw.mes.module.tecdrawsign.repository.DrawLssueRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author mayongfeng
 * @version 1.0.0
 * @ClassName DrawSignService.java
 * @Description TODO
 * @createTime 2021年03月18日 16:16:00
 */
@Service
@SuppressWarnings("all")
public class DrawSignService {

    @Autowired
    private DrawSignMapper drawSignMapper;
    @Autowired
    private DrawLssueRepository drawLssueRepository;


/****************************************************图纸签收***********************************************************/

    /**查询所有的图纸变更记录*/
    public List<DrawSign> getAll(DrawSign drawSign) {

        return drawSignMapper.getAll(drawSign);
    }


/**************************************************图纸变更签收*********************************************************/

    /**查询所有的图纸变更记录*/
    public List<DrawSign> getChaAll(DrawSign drawSign) {

        return drawSignMapper.getChaAll(drawSign);
    }

    /** 保存到下发科室表*/
    public int submitCj(List<DictEnum> dictEnumList, Integer lssueId,Integer changeType) {
        if(changeType==1){
            drawSignMapper.updateById(lssueId);
        }else if(changeType==2){
            drawSignMapper.updateChaById(lssueId);
        }

        for (DictEnum dictEnum : dictEnumList) {
            DrawLssue drawLssue = new DrawLssue();
            /** 下发记录表Id*/
            drawLssue.setRecordId(lssueId);
            /** 所属科室id*/
            drawLssue.setSectionId(Integer.parseInt(dictEnum.getValue()));
            /** 下发状态:0=未下发，1=已下发*/
            drawLssue.setLssueStatus(1);
            /** 所属科室名称*/
            drawLssue.setSectionName(dictEnum.getName());
            /** 签收状态：0=未签收，1=已签收*/
            drawLssue.setSignStatus(0);
            /** 变更标识1=图纸签收，2=图纸变更签收*/
            drawLssue.setChangeType(changeType);
            drawLssueRepository.save(drawLssue);

        }
        return 1;
    }

    /** 生产运营部签收*/
    public int updateProdSign(Integer id,Integer type) {
        int i = 0;
        if(type == 1){
            i = drawSignMapper.updateProdSign(id);

        }else if(type == 2){
            i = drawSignMapper.updateChaProdSign(id);
        }

        return i;
    }
}
